package com.demo.mapper.system;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.pojo.DTO.DTORoleMenu;
import com.demo.pojo.DTO.DTOUserDept;
import com.demo.pojo.PO.User;
import com.demo.pojo.DTO.DTOUserPost;
import com.demo.pojo.DTO.DTOUserRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select id,name from sys_post")
    public List<DTOUserPost> selectAllPost();
    @Select("select user_id,role_id,role_name from sys_user_role left join sys_role on sys_user_role.role_id = sys_role.id")
    public List<DTOUserRole> selectAllUserRoleAndRole();
    @Select("select * from sys_dept")
    public List<DTOUserDept> selectAllDept();

    @Select("select id from sys_dept where tree_path like #{treePath}")
    public List<String> selectDeptTree(String treePath);

    @Select("select * from sys_user_role left join sys_role on sys_user_role.role_id = sys_role.id where user_id = #{userId} and sys_user_role.is_deleted = 1")
    public List<DTOUserRole> selectUserRole(Integer userId);
    @Update("update sys_user_role set is_deleted = #{isDeleted} where id = #{id} and user_id = #{userId}")
    public Integer updateRole(Integer id ,Integer isDeleted, Integer userId);
    @Select("select * from sys_user_role where user_id = #{userId} ")
    public List<DTOUserRole> selectAllUserRole(Integer userId);
    @Insert("insert into sys_user_role (role_id,user_id,is_deleted) value (#{roleId},#{userId},#{isDeleted})")
    public int addUserRole(Integer roleId,Integer userId,Integer isDeleted);
    @Select("select user_id from sys_user_role where role_id = #{userRoleId}")
    public List<DTOUserRole> selectRoleId(String userRoleId);
    @Select("select b.id,a.role_id,b.menu_id,b.create_time,b.update_time,b.is_deleted from sys_user_role a left join sys_role_menu b on a.role_id = b.role_id where user_id = #{userId}")
    public List<DTORoleMenu> getRAndMById(Integer userId);
}
